<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\api\validate;
use think\Validate;

class MatchApply extends Validate
{
    protected $personal;
    protected $avg_amount;

    protected $holding_time;
    protected $holding_address;
    protected $charge;
    protected $mobile;
    protected $organizer;

    /**
     * 验证规则
     */
    protected $rule = [
        'personal' => 'require',
        'avg_amount'   => 'require',
        'holding_time'   => 'require|date',
        'holding_address'   => 'require|length:2,150',
        'charge'   => 'require|length:2,50',
        'mobile'  => 'require|ruleMobile',
        'organizer'  => 'require|length:2,150',
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'personal.require'=>'人数规模不能为空',
        'avg_amount.require'=>'人均金额不能为空',
        'holding_time.require'=>'赛事举办时间不能为空',
        'holding_time.date'=>'赛事举办时间格式不正确',
        'holding_address.require'=>'举办地址不能为空',
        'holding_address.length'=>'举办地址长度为2-150个字符',
        'charge.require'=>'负责人不能为空',
        'charge.length'=>'负责人长度为2-50个字符',
        'mobile.require'=>'负责人手机号不能为空',
        'mobile.ruleMobile'=>'手机号格式不正确',
        'organizer.require'=>'举办方不能为空',
        'organizer.length'=>'举办方长度为2-150字符',
    ];
    public function __construct(array $rules = [], $message = [], $field = [])
    {
        parent::__construct($rules, $message, $field);
    }


    /**
     * 检查手机号格式
     * @param $mobile
     * @return bool
     */
    protected function ruleMobile($mobile)
    {
        $this->setFiled('mobile',$mobile);
        if (!preg_match("/^1\d{10}$/", $mobile)) {
            return false;
        }
        return true;
    }



    protected function setFiled($key,$value)
    {
        $this->$key = $value;
    }

    public function getFiled($key)
    {
        return $this->$key;
    }
}
